package com.njupt.yanglonglong.report.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.njupt.yanglonglong.report.demo.entity.TeamReport;
import com.njupt.yanglonglong.report.demo.mapper.TeamReportMapper;
import com.njupt.yanglonglong.report.demo.service.TeamReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author yangllong
 * @Date 2021/5/29 21:27
 */
@Service
public class TeamReportServiceImpl implements TeamReportService {
    @Autowired
    private TeamReportMapper teamReportMapper;

    @Override
    public TeamReport getTeamReportByTeamIdAndExperId(String team, String experId) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("team_ids", team);
        qw.eq("exper_id", experId);
        return teamReportMapper.selectOne(qw);
    }

    @Override
    public void saveOrUpdate(TeamReport teamReport) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("team_ids", teamReport.getTeamIds());
        qw.eq("exper_id", teamReport.getExperId());
        TeamReport report = teamReportMapper.selectOne(qw);
        if (report != null) {
            // update
            UpdateWrapper uw = new UpdateWrapper();
            uw.eq("team_ids", teamReport.getTeamIds());
            uw.eq("exper_id", teamReport.getExperId());
            teamReportMapper.update(teamReport, uw);
        } else {
            // save
            teamReportMapper.insert(teamReport);
        }
    }
}
